//初始化日历控件读取全部日程
function _initCalendar() {
	PRO.fullcalendar.init(ctx+"/sys/schedule/schedule/getAllSchedule", function (obj) {
		PRO.fullcalendar.show(ctx+"/sys/schedule/schedule/detail", obj.id, obj.type, obj.start, obj.end, obj.trueAllDay);
	});
}
function _typeFilter() {
	var cbxObj = { meeting: true, matter: true, mine: true, other: true };
	$("body").on("click", ".schedule-area-filter input[type='checkbox']", function () {
		var ctg = $(this).attr("id").replace("cbx_", ""),
			meeting = $("#cbx_meeting").prop("checked"),
			matter = $("#cbx_matter").prop("checked"),
			mine = $("#cbx_mycreate").prop("checked"),
			other = $("#cbx_othercreate").prop("checked");

		if (ctg == "meeting" || ctg == "matter") {
			if ((meeting && matter) || (!meeting && !matter)) { cbxObj.meeting = true; cbxObj.matter = true; }
			if (meeting && !matter) { cbxObj.meeting = true; cbxObj.matter = false; }
			if (!meeting && matter) { cbxObj.meeting = false; cbxObj.matter = true; }
		} else {
			if ((mine && other) || (!mine && !other)) { cbxObj.mine = true; cbxObj.other = true; }
			if (mine && !other) { cbxObj.mine = true; cbxObj.other = false; }
			if (!mine && other) { cbxObj.mine = false; cbxObj.other = true; }
		}
		
		if ((cbxObj.mine && cbxObj.other) || (!cbxObj.mine && !cbxObj.other)) { // AllSchedule
			if (cbxObj.meeting && !cbxObj.matter) { _getSchedule("all", 0); } //会议
			else if (!cbxObj.meeting && cbxObj.matter) { _getSchedule("all", 1); } //事项
			else { _getSchedule("all", -1); } //全部
		} else {
			if (cbxObj.mine && !cbxObj.other) { // MyCreateSchedule
				if (cbxObj.meeting && !cbxObj.matter) { _getSchedule("mine", 0); } //会议
				else if (!cbxObj.meeting && cbxObj.matter) { _getSchedule("mine", 1); } //事项
				else { _getSchedule("mine", -1); } //全部
			}
			else if (!cbxObj.mine && cbxObj.other) { // OthersCreateSchedule
				if (cbxObj.meeting && !cbxObj.matter) { _getSchedule("other", 0); } //会议
				else if (!cbxObj.meeting && cbxObj.matter) { _getSchedule("other", 1); } //事项
				else { _getSchedule("other", -1); } //全部
			}
		}
		
	});
}

function _getSchedule(state, type) {
	$("#calendar").fullCalendar("destroy");
	switch (state) {
		case "all":
			PRO.fullcalendar.init(ctx+"/sys/schedule/schedule/getAllSchedule?type=" + type, function (obj) {
				PRO.fullcalendar.show(ctx+"/sys/schedule/schedule/detail", obj.id, obj.type, obj.start, obj.end, obj.allDay);
			});
			break;
		case "mine":
			PRO.fullcalendar.init(ctx+"/sys/schedule/schedule/getMyCreateSchedule?type=" + type, function (obj) {
				PRO.fullcalendar.show(ctx+"/sys/schedule/schedule/detail", obj.id, obj.type, obj.start, obj.end, obj.allDay);
			});
			break;
		case "other":
			PRO.fullcalendar.init(ctx+"/sys/schedule/schedule/getOthersCreateSchedule?type=" + type, function (obj) {
				PRO.fullcalendar.show(ctx+"/sys/schedule/schedule/detail", obj.id, obj.type, obj.start, obj.end, obj.allDay);
			});
			break;
		default:
			break;
	}
}


$(function () {
	_initCalendar();
	_typeFilter();
});
